#pragma once
#include "HashTable.h"

template<class K, class V, class Hash = hash_bucket::HashFunc<K>>
class Unordered_Map
{
	struct MapKeyOfT
	{
		const K& operator()(const pair<K, V>& kv)
		{
			return kv.first;
		}
	};
public:
	typedef typename hash_bucket::HashTable<K, pair<const K, V>, MapKeyOfT, Hash>::Iterator iterator;
	typedef typename hash_bucket::HashTable<K, pair<const K, V>, MapKeyOfT, Hash>::Const_Iterator const_iterator;

	const_iterator begin() const
	{
		return _mht.Begin();
	}

	const_iterator end() const
	{
		return _mht.End();
	}

	iterator begin()
	{
		return _mht.Begin();
	}

	iterator end()
	{
		return _mht.End();
	}

	iterator find(const pair<K, V>& kv)
	{
		return _mht.Find(kv.first);
	}

	pair<iterator, bool> insert(const pair<K, V>& kv)
	{
		return _mht.Insert(kv);
	}

	V& operator[](const K& key)
	{
		pair<iterator, bool> ret = insert({ key, V() });
		return ret.first->second;
	}

private:
	hash_bucket::HashTable<K, pair<const K, V>, MapKeyOfT, Hash> _mht;
};

